package com.y.architecture.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

import com.y.architecture.R;
import com.y.architecture.base.BaseActivity;
import com.zhengsr.viewpagerlib.bean.PageBean;
import com.zhengsr.viewpagerlib.callback.PageHelperListener;
import com.zhengsr.viewpagerlib.indicator.TransIndicator;
import com.zhengsr.viewpagerlib.view.GlideViewPager;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class FirstGuideActivity extends BaseActivity {

    @BindView(R.id.splase_viewpager)
    GlideViewPager viewPager;

    @BindView(R.id.splase_bottom_layout)
    TransIndicator linearLayout;

    @BindView(R.id.splase_start_btn)
    Button button;

    private static final Integer[] RES = {R.mipmap.guide1,R.mipmap.guide2,R.mipmap.guide3,
            R.mipmap.guide4};

    @Override
    public int getContentView() {
        return R.layout.activity_first_guide;
    }

    @Override
    public void initViews(Bundle savedInstanceState) {
        //先把本地的图片 id 装进 list 容器中
        List<Integer> images = new ArrayList<>();
        for (int i = 0; i < RES.length; i++) {
            images.add(RES[i]);
        }
        //配置pagerbean，这里主要是为了viewpager的指示器的作用，注意记得写上泛型
        PageBean bean = new PageBean.Builder<Integer>()
                .setDataObjects(images)
                .setIndicator(linearLayout)
                .setOpenView(button)
                .builder();

        // 把数据添加到 viewpager中，并把view提供出来，这样除了方便调试，也不会出现一个view，多个
        // parent的问题，这里在轮播图比较明显
        viewPager.setPageListener(bean, R.layout.image_layout, new PageHelperListener() {
            @Override
            public void getItemView(View view, Object data) {
                ImageView imageView = view.findViewById(R.id.icon);
                imageView.setImageResource((Integer) data);
            }
        });

        //点击实现跳转功能
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(FirstGuideActivity.this,MainActivity.class));
                Toast.makeText(FirstGuideActivity.this, "回到首页", Toast.LENGTH_SHORT).show();
                finish();
            }
        });
    }

}
